<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Lap_lulus extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('mdl_lap_lulus');
		$this->load->library('Excel_generator');
	}
	
	function index(){
		$this->load->view('lap_lulus');
	}
	
	
	function grid(){
		$data = $this->mdl_lap_lulus->getdata();
		echo $this->mdl_lap_lulus->togrid($data['row_data'], $data['row_count']);
	}
	
	/*function pdf(){
		# inisialisasi library
		$this->load->library('our_pdf');
		$this->our_pdf->FPDF('L', 'mm', 'A4');
		define('FPDF_FONTPATH',APPPATH."libraries/fpdf/font/");
		
		// ambil data dari tabel
		$pdfdata = $this->mdl_lap_lulus->get_pdf();
		if (count($pdfdata['row'])==0){
			echo "Data Tidak Tersedia";
			return;
		}
		
		# create pdf
		$this->our_pdf->Open();
		$this->our_pdf->addPage();
		
		// judul laporan
		$this->our_pdf->setFont('arial','B',16);
		$posY = 35;
		$posX = 10;
		$midX = 150;
		$title = 'Data Mahasiswa Lulus Seleksi';
		$textPosX = $midX - ($this->our_pdf->GetStringWidth($title) / 2);
		$this->our_pdf->text($textPosX,$posY,$title);
		
		# setting coloumn
		$this->our_pdf->setFont('Arial','B',9);
		$this->our_pdf->setFillColor(255,255,255);
		$posY += 6;
		$this->our_pdf->setXY($posX,$posY);
		
		// init column
		$col_width = array();
		$col_align = array();
		$col_caption = array();
		$col_val_align = array();
		foreach($pdfdata['column'] as $col){
			array_push($col_width, 		$col['width']);
			array_push($col_align, 		$col['align']);
			array_push($col_caption, 	$col['caption']);
			array_push($col_val_align, 	$col['val_align']);
		}
		
		// set column option
		$this->our_pdf->SetWidths($col_width);
		$this->our_pdf->SetAligns($col_align);
		$this->our_pdf->Row($col_caption);
		
		# setting row
		$posY = 39;
		$this->our_pdf->setFont('arial','',9);	
		$this->our_pdf->setFillColor(255,255,255);
		
		$this->our_pdf->SetAligns($col_val_align);
		
		// insert record
		foreach($pdfdata['row'] as $row){
			$this->our_pdf->Row($row);
		}
		
		// finish
		$this->our_pdf->AliasNbPages();
		$this->our_pdf->Output("Data Lulus Seleksi.pdf", "I");
	}*/
	
	function laporan_pdf($kd_prodi, $PMBPeriodID){
		 $this->load->library('HTML2PDF');
		 $html2pdf = new HTML2PDF('L', 'A4', 'fr');
		 $html2pdf->setDefaultFont('Arial');
		
		//filter
		#get filter
		$fil['kd_prodi'] = $kd_prodi;
		$fil['PMBPeriodID'] = $PMBPeriodID;
		
		 //$data['nama'] = 'indriyanto';
		 $data['namaUniv'] = 'UNIVERSITAS OTTOW GEISSLER';
		 $data['alamatUniv'] = 'Jln. Perkutut Kotaraja, Telp.(0967)581562';
		 $data['kotaUniv'] = 'Jayapura, Papua';
		 // ambil data dari tabel
		$data['data_pdf'] = $this->mdl_lap_lulus->get_pdf($fil);
		
		
		/* if (count($da['row'])==0){
			echo "Data Tidak Tersedia";
			return;
		} */
		
		
		 $konten = $this->load->view('lulus_laporan',$data,true);
		
         $html2pdf->writeHTML($konten, false);
        
		 $html2pdf->Output('lulus_seleksi.pdf');
	}
	
	function laporan_excel() {			
		$query = $this->db->get('pmb_seleksi');
			$this->excel_generator->set_query($query);
			$this->excel_generator->set_header(array('Periode PMB', 'No Pendaftaran', 'Nama', 'Tempat Lahir', 'Tgl Lahir', 'Kota', ' Alamat', 'No Telp', 'Kode Prodi', 'Status'));
			$this->excel_generator->set_column(array('PMBPeriodID', 'no_pendaftaran', 'nama', 'tempat_lahir', 'tgl_lahir', 'kota', 'alamat', 'no_telp', 'kd_prodi', 'status'));
			$this->excel_generator->set_width(array(10, 10, 25, 15, 15, 10, 25, 10, 10, 10));
			$this->excel_generator->exportTo2007('Peserta Lulus PMB');
	}
}